﻿Imports System.Data
Imports ADOEntityKYC
Partial Class KYC_NonIndividualBoard
    Inherits Web.UI.BasePage

#Region " Variable Gobal "

    Dim ds As DataSet
    Dim clsRiskLevel As clsRiskLevel = New clsRiskLevel
    Dim clsDatabase As clsDatabase
    Dim KYCEntity As KYCEntities = New KYCEntities
    Dim clsSessionMenuRight As clsSessionMenuRight = New clsSessionMenuRight
    Dim TypeKYC As Integer = 0
    Dim CustSeq As Integer = 0
    Dim clsCheckLanguage As clsCheckLanguage
    Dim clsCheckID As clsCheckID
    Dim strMsg As String = ""
    Dim index As Integer = -1

#End Region

#Region "Even Page"

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            btnSearch.Attributes.Add("onclick", "NoDoubleSubmit();")
            'btnCompile.Attributes.Add("onclick", "NoDoubleSubmitCompile();")

            btnCompile.Attributes.Add("onClick", "NoDoubleSubmitCompile(); myDialog();")

            ds = Session("ds")
            index = Request.QueryString("index")
            TypeKYC = Request.QueryString("TypeKYC")
            CustSeq = Request.QueryString("CUSTSEQ")
            'Session("CustSeq") = CustSeq

            clsSessionMenuRight = Session("clsMenuRight")

            If Not TypeKYC = 4 Then
                btnCancel.Attributes.Add("onclick", "return confirm('" + String.Format(Resources.resMsgKYC.msgCancle) + "')")
            End If

            If Not IsPostBack Then
                chkIsLogin()
                loadDataToDropDown()
                CreateControlMP()

                lblCustSEQ.Text = Request.QueryString("CUSTSEQ")
                lblTypeKYC.Text = Request.QueryString("TypeKYC")

                hdfID.Value = Request.QueryString("UNIQUEID")

                If index > -1 Then 'แก้ไขข้อมูล
                    BindingData()
                    indexOccupationChanging1()
                    indexOccupationChanging2()
                    indexOccupationChanging3()
                    indexBizChanging1()
                    indexBizChanging2()
                    indexBizChanging3()
                    Session("CustSeqBoard") = CustSeq

                    If Not ds.Tables("dsCustomerCom").Rows(index)("CreateBy") Is DBNull.Value Then
                        If Not ds.Tables("dsCustomerCom").Rows(index)("CreateBy") = "AutoGenPK" Then
                            btnHistory.Visible = False
                        Else
                            btnHistory.Visible = True
                        End If
                    Else
                        btnHistory.Visible = True
                    End If

                Else
                    PanelCust.Enabled = False
                    btnHistory.Visible = False
                End If

                If TypeKYC = 4 Then
                    'compileCDD()
                    txtRiskLevel.Text = "ลูกค้ามีความเสี่ยงระดับ " + CStr(ds.Tables("dsCustomerCom").Rows(index)("AMLCDD"))
                    txtReason.Text = ds.Tables("dsCustomerCom").Rows(index)("AMLREASON").ToString

                    Panel1.Enabled = False
                    btnCancel.Text = "ปิด"
                    ' btnSave.Visible = False
                End If

            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        Session("ds") = ds
    End Sub

#End Region

#Region "SetForm"

    Sub CreateControlMP()
        Dim img As Image = CType(Master.FindControl("imgHead"), Image)
        img.ImageUrl = "~/img/Individual.jpg"

        Dim page As Label = CType(Master.FindControl("lblPage"), Label)
        page.Text = "ประเมินความเสี่ยง ผู้ถือหุ้น"
    End Sub

#End Region

#Region "Event Dropdrown"

    Protected Sub ddlOccupation1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlOccupation1.SelectedIndexChanged
        indexOccupationChanging1()
    End Sub

    Protected Sub ddlBusiness1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBusiness1.SelectedIndexChanged
        indexBizChanging1()
    End Sub

    Protected Sub ddlOccupation2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlOccupation2.SelectedIndexChanged
        indexOccupationChanging2()
    End Sub

    Protected Sub ddlBusiness2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBusiness2.SelectedIndexChanged
        indexBizChanging2()
    End Sub

    Protected Sub ddlOccupation3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlOccupation3.SelectedIndexChanged
        indexOccupationChanging3()
    End Sub

    Protected Sub ddlBusiness3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlBusiness3.SelectedIndexChanged
        indexBizChanging3()
    End Sub

    Protected Sub ddlPrefixTH_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPrefixTH.SelectedIndexChanged
        ddlPrefixEN.SelectedValue = ddlPrefixTH.SelectedValue
    End Sub

    Protected Sub ddlPrefixEN_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPrefixEN.SelectedIndexChanged
        ddlPrefixTH.SelectedValue = ddlPrefixEN.SelectedValue
    End Sub

#End Region

#Region "Event Button"

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Try
            FindCustomer()
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
        Try
            lblMsg.Visible = False
            ddlUniqueType.Enabled = True
            ddlUniqueType.SelectedIndex = -1
            txtUniqueID.Enabled = True
            txtUniqueID.Text = ""

            lblCustSEQ.Text = 0
            ddlPrefixTH.SelectedIndex = -1
            txtNameTh1.Text = ""
            txtNameTh2.Text = ""
            txtNameTh3.Text = ""
            ddlPrefixEN.SelectedIndex = -1
            txtNameEn1.Text = ""
            txtNameEn2.Text = ""
            txtNameEn3.Text = ""
            ddlNationality.SelectedIndex = -1
            ddlOccupation1.SelectedIndex = -1
            txtOccOther1.Text = ""
            ddlOccupation2.SelectedIndex = -1
            txtOccOther2.Text = ""
            ddlOccupation3.SelectedIndex = -1
            txtOccOther3.Text = ""
            ddlBusiness1.SelectedIndex = -1
            txtBizOther1.Text = ""
            ddlBusiness2.SelectedIndex = -1
            txtBizOther2.Text = ""
            ddlBusiness3.SelectedIndex = -1
            txtBizOther3.Text = ""
            txtDes1.Text = ""
            txtDes2.Text = ""
            txtDes3.Text = ""
            ddlIncomeSource1.SelectedIndex = -1
            ddlIncomeSource2.SelectedIndex = -1
            ddlIncomeSource3.SelectedIndex = -1
            ddlPosition.SelectedIndex = -1

            ddlNationality.SelectedValue = 202
            ddlIncomeSource1.SelectedValue = 202

            lblCustCode.Text = "เลขประจำตัวลูกค้า : -"

            PanelCust.Enabled = False
            statusValidationFalse()
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnCompile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCompile.Click
        Try
            If (Panel2.Enabled = True) Then
                If Session("chkKYC") = True Then
                    GoTo compile
                End If

                If checkBeforeCompile() = True Then
compile:

                    compileCDD()

                Else

                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & strMsg & "')", True)

                    ' btnSave.Visible = False
                    btnReport.Visible = False

                    txtRiskLevel.Text = ""
                    lblLevel.Text = 0
                    txtReason.Text = ""
                    txtRiskLevel.BackColor = Drawing.Color.White

                End If

                Session("chkKYC") = Nothing
                Panel2.Enabled = False
                btnCompile.Visible = False
                btnEditCompile.Visible = True
                btnReport.Visible = True
            Else
                Panel2.Enabled = True
                btnCompile.Visible = True
                btnEditCompile.Visible = False
                btnReport.Visible = False
            End If
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnHistory_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHistory.Click
        Try

            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.open('CDDHistory.aspx?CUSTSEQ=" & CInt(CustSeq) & "&CUSTTYPE=1" & "','_blank','scrollbars=1,Width:800px, Height:600px')", True)

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click

        Try
            'Session("TypeKYC") = Nothing
            'Session("CustSeq") = Nothing

            If ddlPosition.SelectedIndex = 0 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgAlertKYC.NotPosition & "')", True)
                Image7.ImageUrl = "~/img/icon/cancel.png"
                Image7.Visible = True
                Exit Sub
            End If

            If Not (hdfID.Value = txtUniqueID.Text.Trim) Then
                If Not (chkCardIdDuplicate(txtUniqueID.Text.Trim)) Then
                    strMsg = "เลขที่บัตร " + txtUniqueID.Text + " ได้มีการกรอกข้อมูลผู้เกี่ยวข้องแล้ว "
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & strMsg & "')", True)
                    Exit Sub
                End If
            End If

            If index = -1 Then
                saveData()
            Else 'แก้ไขข้อมูล
                updateData()
            End If
            Session("strReason") = Nothing
            Session("ds") = ds
            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.close();", True)

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try

    End Sub

    Protected Sub btnReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReport.Click
        Try
            If ddlPosition.SelectedIndex = 0 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgAlertKYC.NotPosition & "')", True)
                Image7.ImageUrl = "~/img/icon/cancel.png"
                Image7.Visible = True
                Exit Sub
            End If

            If Not (hdfID.Value = txtUniqueID.Text.Trim) Then
                If Not (chkCardIdDuplicate(txtUniqueID.Text.Trim)) Then
                    strMsg = "เลขที่บัตร " + txtUniqueID.Text + " ได้มีการกรอกข้อมูลผู้เกี่ยวข้องแล้ว "
                    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & strMsg & "')", True)
                    Exit Sub
                End If
            End If

            If index = -1 Then
                saveData()
            Else 'แก้ไขข้อมูล
                updateData()
            End If
            'ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.showModalDialog('../Form/KYCResult.aspx?uniqueID=" & txtUniqueID.Text.Trim & "&" _
            '                                  & "PrefixTH=" & ddlPrefixTH.Text & "&" _
            '                                  & "NameTh1=" & txtNameTh1.Text.Trim & "&" _
            '                                  & "NameTh2=" & txtNameTh2.Text.Trim & "&" _
            '                                  & "NameTh3=" & txtNameTh3.Text.Trim & "&" _
            '                                  & "PrefixEN=" & ddlPrefixEN.Text & "&" _
            '                                  & "NameEN1=" & txtNameEn1.Text.Trim & "&" _
            '                                  & "NameEN2=" & txtNameEn2.Text.Trim & "&" _
            '                                  & "NameEN3=" & txtNameEn3.Text.Trim & "&" _
            '                                  & "Nationality=" & ddlNationality.Text & "&" _
            '                                  & "Occupation1=" & ddlOccupation1.Text & "&" _
            '                                  & "OccOther1=" & txtOccOther1.Text.Trim & "&" _
            '                                  & "Business1=" & ddlBusiness1.Text & "&" _
            '                                  & "BizOther1=" & txtBizOther1.Text.Trim & "&" _
            '                                  & "Des1=" & txtDes1.Text.Trim & "&" _
            '                                  & "Occupation2=" & ddlOccupation2.Text & "&" _
            '                                  & "OccOther2=" & txtOccOther2.Text.Trim & "&" _
            '                                  & "Business2=" & ddlBusiness2.Text & "&" _
            '                                  & "BizOther2=" & txtBizOther2.Text.Trim & "&" _
            '                                  & "Des2=" & txtDes2.Text.Trim & "&" _
            '                                  & "Occupation3=" & ddlOccupation3.Text & "&" _
            '                                  & "OccOther3=" & txtOccOther3.Text.Trim & "&" _
            '                                  & "Business3=" & ddlBusiness3.Text & "&" _
            '                                  & "BizOther3=" & txtBizOther3.Text.Trim & "&" _
            '                                  & "Des3=" & txtDes3.Text.Trim & "&" _
            '                                  & "IncomeSource1=" & ddlIncomeSource1.Text & "&" _
            '                                  & "IncomeSource2=" & ddlIncomeSource2.Text & "&" _
            '                                  & "IncomeSource3=" & ddlIncomeSource3.Text & "&" _
            '                                  & "RiskLevel=" & txtRiskLevel.Text.Trim & "&" _
            '                                  & "Reason=" & txtReason.Text.Trim & "'" _
            '                                  & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)

            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.showModalDialog('../Form/KYCResult.aspx?uniqueID=" & txtUniqueID.Text.Trim & "&" _
                                            & "PrefixTH=" & ddlPrefixTH.Text & "&" _
                                            & "NameTh1=" & txtNameTh1.Text.Trim & "&" _
                                            & "NameTh2=" & txtNameTh2.Text.Trim & "&" _
                                            & "NameTh3=" & txtNameTh3.Text.Trim & "&" _
                                            & "PrefixEN=" & ddlPrefixEN.Text & "&" _
                                            & "NameEN1=" & txtNameEn1.Text.Trim & "&" _
                                            & "NameEN2=" & txtNameEn2.Text.Trim & "&" _
                                            & "NameEN3=" & txtNameEn3.Text.Trim & "&" _
                                            & "Nationality=" & ddlNationality.Text & "&" _
                                            & "Occupation1=" & ddlOccupation1.Text & "&" _
                                            & "OccOther1=" & txtOccOther1.Text.Trim & "&" _
                                            & "Business1=" & ddlBusiness1.Text & "&" _
                                            & "BizOther1=" & txtBizOther1.Text.Trim & "&" _
                                            & "Des1=" & txtDes1.Text.Trim & "&" _
                                            & "Occupation2=" & ddlOccupation2.Text & "&" _
                                            & "OccOther2=" & txtOccOther2.Text.Trim & "&" _
                                            & "Business2=" & ddlBusiness2.Text & "&" _
                                            & "BizOther2=" & txtBizOther2.Text.Trim & "&" _
                                            & "Des2=" & txtDes2.Text.Trim & "&" _
                                            & "Occupation3=" & ddlOccupation3.Text & "&" _
                                            & "OccOther3=" & txtOccOther3.Text.Trim & "&" _
                                            & "Business3=" & ddlBusiness3.Text & "&" _
                                            & "BizOther3=" & txtBizOther3.Text.Trim & "&" _
                                            & "Des3=" & txtDes3.Text.Trim & "&" _
                                            & "IncomeSource1=" & ddlIncomeSource1.Text & "&" _
                                            & "IncomeSource2=" & ddlIncomeSource2.Text & "&" _
                                            & "IncomeSource3=" & ddlIncomeSource3.Text & "&" _
                                            & "RiskLevel=" & txtRiskLevel.Text.Trim & "'" _
                                            & ", null, 'status:no; dialogWidth:1000px; dialogHeight:600px; help:no; scroll:yes; menubar:no; resizable:no')", True)

            Session("ds") = ds

           

            SaveLogPrint(2)
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

    Protected Sub btnKYC_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnKYC.Click

    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Try
            'Session("TypeKYC") = Nothing
            'Session("CustSeq") = Nothing

            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "window.close();", True)
        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, _
                                                            UpdatePanel1.GetType(), _
                                                            "clientScript", _
                                                            "alert('" + ex.Message.Replace("'", "") + "')", _
                                                            True)
        End Try
    End Sub

#End Region

#Region "Function"

    Private Sub loadDataToDropDown()
        Try
            Dim clsDropDown As New clsMasterDropDown

            clsDropDown.setIDTypeToDdl(ddlUniqueType)
            clsDropDown.setPrefixTHToDdl(ddlPrefixTH, 1)
            clsDropDown.setPrefixENToDdl(ddlPrefixEN, 1)
            clsDropDown.setNationalityToDdl(ddlNationality)
            clsDropDown.setOccupationToDdl(ddlOccupation1, 1)
            clsDropDown.setBusinessToDdl(ddlBusiness1)
            clsDropDown.setOccupationToDdl(ddlOccupation2, 1)
            clsDropDown.setBusinessToDdl(ddlBusiness2)
            clsDropDown.setOccupationToDdl(ddlOccupation3, 1)
            clsDropDown.setBusinessToDdl(ddlBusiness3)
            clsDropDown.setCountyToDdl(ddlIncomeSource1)
            clsDropDown.setCountyToDdl(ddlIncomeSource2)
            clsDropDown.setCountyToDdl(ddlIncomeSource3)

            clsDropDown.setPositionToDdl(ddlPosition)

            ddlNationality.SelectedValue = 202
            ddlIncomeSource1.SelectedValue = 202


            clsDropDown = Nothing
        Catch ex As Exception
            WriteError(ex, "loadDataToDropDown", "NonIndividualBoard")
           Throw ex
        End Try
    End Sub

    Private Sub AutoInput()
        Try
            txtUniqueID.Text = Request.QueryString("uniqueID")
            txtNameTh1.Text = Request.QueryString("FIRSTNAMETH")
            txtNameTh2.Text = Request.QueryString("MIDNAMETH")
            txtNameTh3.Text = Request.QueryString("LASTNAMETH")
            txtNameEn1.Text = Request.QueryString("FIRSTNAMEEN")
            txtNameEn2.Text = Request.QueryString("MIDNAMEEN")
            txtNameEn3.Text = Request.QueryString("LASTNAMEEN")
        Catch ex As Exception
            Throw ex
        End Try

    End Sub

    Private Sub FindCustomer()
        Try
            clsCheckID = New clsCheckID
            If ddlUniqueType.SelectedIndex = 0 Then
                Image1.ImageUrl = "~/img/icon/cancel.png"
                Image1.Visible = True
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgAlertKYC.NotIDType & "')", True)

            ElseIf txtUniqueID.Text.Trim = "" Then
                Image1.ImageUrl = "~/img/icon/cancel.png"
                Image1.Visible = True
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgAlertKYC.NotID & "')", True)

            ElseIf ddlUniqueType.SelectedValue = 1 And Not txtUniqueID.Text.Trim.Length = 13 Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgID & "')", True)

            ElseIf ddlUniqueType.SelectedValue = 1 And Not (clsCheckID.chkIDcard(txtUniqueID.Text.Trim)) Then
                Image1.ImageUrl = "~/img/icon/cancel.png"
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & String.Format(clsCheckID.Msg) & "')", True)
                Exit Sub

            Else

                'Dim qryCust = (From cust In KYCEntity.MCUSTOMER _
                '          Group Join r In KYCEntity.MCOMPRELATION On cust.CUSTSEQ Equals r.REFCUSTSEQ _
                '          Into ref = Group From leftjoinref In ref.DefaultIfEmpty _
                '          Where cust.UNIQUEID = txtUniqueID.Text.Trim And cust.CUSTIDTYPE = ddlUniqueType.SelectedValue
                '          Select cust, leftjoinref.POCODE).ToList

                Dim qryCust = (From cust In KYCEntity.MCUSTOMER _
                        Where cust.UNIQUEID = txtUniqueID.Text.Trim
                        Select cust.CUSTSEQ, cust.CUSTCODE,
                        cust.THPREFIX, cust.THFIRSTNAME, cust.THMIDNAME, cust.THLASTNAME,
                        cust.ENPREFIX, cust.ENFIRSTNAME, cust.ENMIDNAME, cust.ENLASTNAME,
                        cust.NATIONALITY, cust.OCCUPATIONTYPE1, cust.OCCUPATIONTYPE2, cust.OCCUPATIONTYPE3,
                        cust.OCCUPATIONTYPEOTHER1, cust.OCCUPATIONTYPEOTHER2, cust.OCCUPATIONTYPEOTHER3,
                        cust.BIZDESC1, cust.BIZDESC2, cust.BIZDESC3, cust.BIZTYPE1, cust.BIZTYPE2, cust.BIZTYPE3,
                        cust.BIZTYPEOTHER1, cust.BIZTYPEOTHER2, cust.BIZTYPEOTHER3,
                        cust.INCOMESOURCE1, cust.INCOMESOURCE2, cust.INCOMESOURCE3,
                        cust.AMLCDDSAS, cust.AMLREASONSAS
                        ).ToList

                PanelCust.Enabled = True

                If qryCust.Count = 0 Then
                    lblMsg.Visible = True
                    lblCustSEQ.Text = 0
                    Session("CustSeqBoard") = 0
                    Session("TypeKYCBoard") = 1
                Else
                    lblMsg.Visible = False
                    ddlUniqueType.Enabled = False
                    txtUniqueID.Enabled = False

                    hdfUniqueID.Value = txtUniqueID.Text
                    lblTypeKYC.Text = 2
                    Session("TypeKYCBoard") = 2
                    Session("CustSeqBoard") = qryCust(0).CUSTSEQ
                    lblCustSEQ.Text = qryCust(0).CUSTSEQ
                    Try
                        ddlPrefixTH.SelectedValue = qryCust(0).THPREFIX
                    Catch ex As Exception

                    End Try

                    txtNameTh1.Text = qryCust(0).THFIRSTNAME
                    txtNameTh2.Text = qryCust(0).THMIDNAME
                    txtNameTh3.Text = qryCust(0).THLASTNAME
                    Try
                        ddlPrefixEN.SelectedValue = qryCust(0).ENPREFIX
                    Catch ex As Exception

                    End Try

                    txtNameEn1.Text = qryCust(0).ENFIRSTNAME
                    txtNameEn2.Text = qryCust(0).ENMIDNAME
                    txtNameEn3.Text = qryCust(0).ENLASTNAME
                    Try
                        If Not qryCust(0).NATIONALITY Is Nothing Then
                            ddlNationality.SelectedValue = qryCust(0).NATIONALITY
                        End If
                    Catch ex As Exception

                    End Try

                    Try
                        If Not qryCust(0).OCCUPATIONTYPE1 Is Nothing Then
                            ddlOccupation1.SelectedValue = qryCust(0).OCCUPATIONTYPE1
                        End If
                    Catch ex As Exception

                    End Try


                    txtOccOther1.Text = qryCust(0).OCCUPATIONTYPEOTHER1
                    Try

                    Catch ex As Exception
                        If Not qryCust(0).OCCUPATIONTYPE2 Is Nothing Then
                            ddlOccupation2.SelectedValue = qryCust(0).OCCUPATIONTYPE2
                        End If
                    End Try

                    txtOccOther2.Text = qryCust(0).OCCUPATIONTYPEOTHER2

                    Try
                        If Not qryCust(0).OCCUPATIONTYPE3 Is Nothing Then
                            ddlOccupation3.SelectedValue = qryCust(0).OCCUPATIONTYPE3
                        End If
                    Catch ex As Exception

                    End Try

                    txtOccOther3.Text = qryCust(0).OCCUPATIONTYPEOTHER3

                    Try
                        If Not qryCust(0).BIZTYPE1 Is Nothing Then
                            ddlBusiness1.SelectedValue = qryCust(0).BIZTYPE1
                        End If
                    Catch ex As Exception

                    End Try

                    txtBizOther1.Text = qryCust(0).BIZTYPEOTHER1

                    Try
                        If Not qryCust(0).BIZTYPE2 Is Nothing Then
                            ddlBusiness2.SelectedValue = qryCust(0).BIZTYPE2
                        End If
                    Catch ex As Exception

                    End Try

                    txtBizOther2.Text = qryCust(0).BIZTYPEOTHER2

                    Try
                        If Not qryCust(0).BIZTYPE3 Is Nothing Then
                            ddlBusiness3.SelectedValue = qryCust(0).BIZTYPE3
                        End If
                    Catch ex As Exception

                    End Try


                    txtBizOther3.Text = qryCust(0).BIZTYPEOTHER3

                    txtDes1.Text = qryCust(0).BIZDESC1
                    txtDes2.Text = qryCust(0).BIZDESC2
                    txtDes3.Text = qryCust(0).BIZDESC3

                    Try
                        If Not qryCust(0).INCOMESOURCE1 Is Nothing Then
                            ddlIncomeSource1.SelectedValue = qryCust(0).INCOMESOURCE1
                        End If
                    Catch ex As Exception

                    End Try

                    Try
                        If Not qryCust(0).INCOMESOURCE2 Is Nothing Then
                            ddlIncomeSource2.SelectedValue = qryCust(0).INCOMESOURCE2
                        End If
                    Catch ex As Exception

                    End Try

                    Try
                        If Not qryCust(0).INCOMESOURCE3 Is Nothing Then
                            ddlIncomeSource3.SelectedValue = qryCust(0).INCOMESOURCE3
                        End If
                    Catch ex As Exception

                    End Try


                    'If Not qryCust(0).POCODE Is Nothing Then
                    '    ddlPosition.SelectedValue = qryCust(0).POCODE
                    'End If

                    lblCustCode.Text = "เลขประจำตัวลูกค้า : " + qryCust(0).CUSTCODE
                    'Else
                    '    ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgCheckID & "')", True)

                    txtReasonSAS.Text = qryCust(0).AMLREASONSAS

                    hdfAML.Value = Convert.ToString(qryCust(0).AMLCDDSAS)
                End If

            End If

            clsCheckID = Nothing
        Catch ex As Exception
            WriteError(ex, "FindCustomer", "NonIndividualBoard")
            Throw ex
        End Try
    End Sub

     Sub BindingData()
        Try
            ddlUniqueType.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("CUSTIDTYPE")
            txtUniqueID.Text = ds.Tables("dsCustomerCom").Rows(index)("UniqueID")
            hdfUniqueID.Value = ds.Tables("dsCustomerCom").Rows(index)("UniqueID")
            ddlPrefixTH.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("ThPreFix").ToString
            txtNameTh1.Text = ds.Tables("dsCustomerCom").Rows(index)("ThFirstName").ToString
            txtNameTh2.Text = ds.Tables("dsCustomerCom").Rows(index)("ThMidName").ToString
            txtNameTh3.Text = ds.Tables("dsCustomerCom").Rows(index)("ThLastName").ToString
            ddlPrefixEN.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("ENPreFix")
            txtNameEn1.Text = ds.Tables("dsCustomerCom").Rows(index)("EnFirstName").ToString
            txtNameEn2.Text = ds.Tables("dsCustomerCom").Rows(index)("EnMidName").ToString
            txtNameEn3.Text = ds.Tables("dsCustomerCom").Rows(index)("EnLastName").ToString
            ddlNationality.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("Nationality")
            ddlOccupation1.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPE1")
            txtOccOther1.Text = ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPEOTHER1").ToString
            If Not ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPE2") Is DBNull.Value Then
                ddlOccupation2.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPE2")
            End If
            txtOccOther2.Text = ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPEOTHER2").ToString
            If Not ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPE3") Is DBNull.Value Then
                ddlOccupation3.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPE3")
            End If
            txtOccOther3.Text = ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPEOTHER3").ToString
            If Not ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE1") Is DBNull.Value Then
                ddlBusiness1.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE1")
            End If
            txtBizOther1.Text = ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER1").ToString
            If Not ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE2") Is DBNull.Value Then
                ddlBusiness2.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE2")
            End If
            txtBizOther2.Text = ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER2").ToString
            If Not ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE3") Is DBNull.Value Then
                ddlBusiness3.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE3")
            End If
            txtBizOther3.Text = ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER3").ToString

            txtDes1.Text = ds.Tables("dsCustomerCom").Rows(index)("BIZDESC1").ToString
            txtDes2.Text = ds.Tables("dsCustomerCom").Rows(index)("BIZDESC2").ToString
            txtDes3.Text = ds.Tables("dsCustomerCom").Rows(index)("BIZDESC3").ToString

            ddlIncomeSource1.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("IncomeSource1")
            If Not ds.Tables("dsCustomerCom").Rows(index)("IncomeSource2") Is DBNull.Value Then
                ddlIncomeSource2.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("IncomeSource2")
            End If
            If Not ds.Tables("dsCustomerCom").Rows(index)("IncomeSource3") Is DBNull.Value Then
                ddlIncomeSource3.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("IncomeSource3")
            End If

            ddlPosition.SelectedValue = ds.Tables("dsCustomerCom").Rows(index)("Pocode")


            lblRiskNow.Text = "ความเสี่ยงล่าสุด : " + CStr(ds.Tables("dsCustomerCom").Rows(index)("AMLCDD"))
            lblRiskNow.Visible = True

            If ds.Tables("dsCustomerCom").Rows(index)("AMLCDD") = 1 Then
                lblRiskNow.ForeColor = Drawing.Color.Green
            ElseIf ds.Tables("dsCustomerCom").Rows(index)("AMLCDD") = 2 Then
                lblRiskNow.ForeColor = Drawing.Color.Orange
            ElseIf ds.Tables("dsCustomerCom").Rows(index)("AMLCDD") = 3 Then
                lblRiskNow.ForeColor = Drawing.Color.Red
            End If

            If Not ds.Tables("dsCustomerCom").Rows(index)("AMLREASONSAS") Is DBNull.Value Then
                txtReasonSAS.Text = ds.Tables("dsCustomerCom").Rows(index)("AMLREASONSAS")
            End If
            If Not ds.Tables("dsCustomerCom").Rows(index)("AMLCDDSAS") Is DBNull.Value Then
                hdfAML.Value = ds.Tables("dsCustomerCom").Rows(index)("AMLCDDSAS")
            End If


        Catch ex As Exception
            WriteError(ex, "BindingData", "NonIndividualBoard")

            Throw ex
        End Try
    End Sub

#Region "Function Drop Drown"

    Private Sub indexOccupationChanging1()
        If Not ddlOccupation1.SelectedValue = "" Then
            ddlBusiness1.BackColor = Drawing.Color.FromArgb(255, 255, 255)

            If ddlOccupation1.SelectedValue = 98 Then 'กรณีเป็นเจ้าของกิจการ
                txtOccOther1.Visible = False
                lblOther11.Visible = False
                ddlBusiness1.Enabled = True
                ddlBusiness1.BackColor = Drawing.Color.FromArgb(255, 204, 204)

            ElseIf ddlOccupation1.SelectedValue = 99 Then 'ประกอบอาชีพอื่นๆ
                txtOccOther1.Visible = True
                lblOther11.Visible = True
                ddlBusiness1.Enabled = False

                ddlBusiness1.SelectedIndex = 0
                txtBizOther1.Visible = False
                txtBizOther1.Text = ""
                lblOther12.Visible = False
            Else
                txtOccOther1.Visible = False
                txtOccOther1.Text = ""
                lblOther11.Visible = False
                ddlBusiness1.Enabled = False

                ddlBusiness1.SelectedIndex = 0
                txtBizOther1.Visible = False
                txtBizOther1.Text = ""
                lblOther12.Visible = False
            End If
        Else
            txtOccOther1.Visible = False
            txtOccOther1.Text = ""
            lblOther11.Visible = False
            ddlBusiness1.Enabled = False

            ddlBusiness1.SelectedIndex = 0
            txtBizOther1.Visible = False
            txtBizOther1.Text = ""
            lblOther12.Visible = False
        End If
    End Sub

    Private Sub indexBizChanging1()
        If Not ddlBusiness1.SelectedValue = "" Then
            If ddlBusiness1.SelectedValue = 99 Then
                txtBizOther1.Visible = True
                lblOther12.Visible = True
            Else
                txtBizOther1.Visible = False
                txtBizOther1.Text = ""
                lblOther12.Visible = False
            End If
        Else
            txtBizOther1.Visible = False
            txtBizOther1.Text = ""
            lblOther12.Visible = False
        End If
    End Sub

    Private Sub indexOccupationChanging2()

        If Not ddlOccupation2.SelectedValue = "" Then
            ddlBusiness2.BackColor = Drawing.Color.FromArgb(255, 255, 255)

            If ddlOccupation2.SelectedValue = 98 Then 'กรณีเป็นเจ้าของกิจการ
                txtOccOther2.Visible = False
                lblOther21.Visible = False
                ddlBusiness2.Enabled = True
                ddlBusiness2.BackColor = Drawing.Color.FromArgb(255, 204, 204)

            ElseIf ddlOccupation2.SelectedValue = 99 Then 'ประกอบอาชีพอื่นๆ
                txtOccOther2.Visible = True
                lblOther21.Visible = True
                ddlBusiness2.Enabled = False

                ddlBusiness2.SelectedIndex = 0
                txtBizOther2.Visible = False
                txtBizOther2.Text = ""
                lblOther22.Visible = False
            Else
                txtOccOther2.Visible = False
                txtOccOther2.Text = ""
                lblOther21.Visible = False
                ddlBusiness2.Enabled = False

                ddlBusiness2.SelectedIndex = 0
                txtBizOther2.Visible = False
                txtBizOther2.Text = ""
                lblOther22.Visible = False
            End If
        Else
            txtOccOther2.Visible = False
            txtOccOther2.Text = ""
            lblOther21.Visible = False
            ddlBusiness2.Enabled = False

            ddlBusiness2.SelectedIndex = 0
            txtBizOther2.Visible = False
            txtBizOther2.Text = ""
            lblOther22.Visible = False
        End If

    End Sub

    Private Sub indexBizChanging2()
        If Not ddlBusiness2.SelectedValue = "" Then
            If ddlBusiness2.SelectedValue = 99 Then
                txtBizOther2.Visible = True
                lblOther22.Visible = True
            Else
                txtBizOther2.Visible = False
                txtBizOther2.Text = ""
                lblOther22.Visible = False
            End If
        Else
            txtBizOther2.Visible = False
            txtBizOther2.Text = ""
            lblOther22.Visible = False
        End If

    End Sub

    Private Sub indexOccupationChanging3()

        If Not ddlOccupation3.SelectedValue = "" Then
            ddlBusiness3.BackColor = Drawing.Color.FromArgb(255, 255, 255)

            If ddlOccupation3.SelectedValue = 98 Then 'กรณีเป็นเจ้าของกิจการ
                txtOccOther3.Visible = False
                lblOther31.Visible = False
                ddlBusiness3.Enabled = True
                ddlBusiness3.BackColor = Drawing.Color.FromArgb(255, 204, 204)

            ElseIf ddlOccupation3.SelectedValue = 99 Then 'ประกอบอาชีพอื่นๆ
                txtOccOther3.Visible = True
                lblOther31.Visible = True
                ddlBusiness3.Enabled = False

                ddlBusiness3.SelectedIndex = 0
                txtBizOther3.Visible = False
                txtBizOther3.Text = ""
                lblOther32.Visible = False
            Else
                txtOccOther3.Visible = False
                txtOccOther3.Text = ""
                lblOther31.Visible = False
                ddlBusiness3.Enabled = False

                ddlBusiness3.SelectedIndex = 0
                txtBizOther3.Visible = False
                txtBizOther3.Text = ""
                lblOther32.Visible = False
            End If
        Else
            txtOccOther3.Visible = False
            txtOccOther3.Text = ""
            lblOther31.Visible = False
            ddlBusiness3.Enabled = False

            ddlBusiness3.SelectedIndex = 0
            txtBizOther3.Visible = False
            txtBizOther3.Text = ""
            lblOther32.Visible = False
        End If


    End Sub

    Private Sub indexBizChanging3()

        If Not ddlBusiness3.SelectedValue = "" Then

            If ddlBusiness3.SelectedValue = 99 Then
                txtBizOther3.Visible = True
                lblOther32.Visible = True
            Else
                txtBizOther3.Visible = False
                txtBizOther3.Text = ""
                lblOther32.Visible = False
            End If
        Else
            txtBizOther3.Visible = False
            txtBizOther3.Text = ""
            lblOther32.Visible = False
        End If

    End Sub

#End Region

    Private Function checkBeforeCompile() As Boolean
        Try
            clsCheckLanguage = New clsCheckLanguage
            clsCheckID = New clsCheckID
            Dim result As Boolean = True

            If ddlUniqueType.SelectedValue = 1 Then
                If Not txtUniqueID.Text.Trim.Length = 13 Then
                    result = False
                    Image1.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.UniqueComplete + "\n"
                Else
                    If Not txtUniqueID.Text = hdfUniqueID.Value Then
                        If clsCheckID.checkUniqueID1(txtUniqueID.Text, lblTypeKYC.Text, lblCustSEQ.Text) = False Then
                            result = False
                            Image1.ImageUrl = "~/img/icon/cancel.png"
                            clsCheckID = Nothing
                            strMsg = strMsg + Resources.resMsgAlertKYC.UniqueID + "\n"
                        ElseIf Not (clsCheckID.chkIDcard(txtUniqueID.Text.Trim)) Then
                            result = False
                            Image1.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + String.Format(clsCheckID.Msg) + "\n"
                        Else
                            Image1.ImageUrl = "~/img/icon/accept.png"
                        End If
                    Else
                        Image1.ImageUrl = "~/img/icon/accept.png"
                    End If

                End If
            Else
                If txtUniqueID.Text.Trim.Length = 0 Then
                    result = False
                    Image1.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotID + "\n"
                Else
                    Image1.ImageUrl = "~/img/icon/accept.png"
                End If
            End If

            If ddlNationality.SelectedIndex = 0 Then
                If ddlNationality.SelectedValue = 202 Then
                    If ddlPrefixTH.SelectedIndex = 0 And txtNameTh1.Text.Trim = "" And txtNameTh3.Text.Trim = "" Then
                        result = False
                        Image2.ImageUrl = "~/img/icon/cancel.png"
                        strMsg = strMsg + Resources.resMsgAlertKYC.NotNameTH + "\n"
                    Else
                        If ddlPrefixTH.SelectedIndex = 0 Then
                            result = False
                            Image2.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotTHPrefix + "\n"
                            GoTo TH
                        ElseIf txtNameTh1.Text.Trim = "" Then
                            result = False
                            Image2.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotTHFirstName + "\n"
                            GoTo TH
                        ElseIf txtNameTh3.Text.Trim = "" Then
                            result = False
                            Image2.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotTHLastName + "\n"
                            GoTo TH
                        ElseIf clsCheckLanguage.checkLanguageTH(txtNameTh1.Text.Trim, txtNameTh2.Text.Trim, txtNameTh3.Text.Trim) = False Then
                            strMsg = strMsg + Resources.resMsgKYC.msgTH + "\n"
                            result = False
                            Image2.ImageUrl = "~/img/icon/cancel.png"
                        Else
                            Image2.ImageUrl = "~/img/icon/accept.png"
                        End If
                    End If
                End If
            End If

TH:
            If ddlPrefixEN.SelectedIndex = 0 And txtNameEn1.Text.Trim = "" And txtNameEn3.Text.Trim = "" Then
                result = False
                Image3.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotNameEN + "\n"
            Else
                If ddlPrefixEN.SelectedIndex = 0 Then
                    result = False
                    Image3.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotENPrefix + "\n"
                    GoTo EN
                ElseIf txtNameEn1.Text.Trim = "" Then
                    result = False
                    Image3.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotENFirstName + "\n"
                    GoTo EN
                ElseIf txtNameEn3.Text.Trim = "" Then
                    result = False
                    Image3.ImageUrl = "~/img/icon/cancel.png"
                    strMsg = strMsg + Resources.resMsgAlertKYC.NotENLastName + "\n"
                    GoTo EN
                ElseIf clsCheckLanguage.checkLanguageEN(txtNameEn1.Text.Trim, txtNameEn2.Text.Trim, txtNameEn3.Text.Trim) = False Then
                    strMsg = strMsg + Resources.resMsgKYC.msgEN + "\n"
                    result = False
                    Image3.ImageUrl = "~/img/icon/cancel.png"
                Else
                    Image3.ImageUrl = "~/img/icon/accept.png"
                End If
            End If

EN:
            If ddlNationality.SelectedIndex = 0 Then
                result = False
                Image4.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotNationality + "\n"
            Else
                Image4.ImageUrl = "~/img/icon/accept.png"
            End If

            If ddlOccupation1.SelectedIndex = 0 Then
                result = False
                Image5.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotOccupation + " 1" + "\n"
            Else
                If Not ddlOccupation1.SelectedIndex = 0 Then
                    If ddlOccupation1.SelectedValue = 98 Then 'เจ้าของ
                        If ddlBusiness1.SelectedIndex = 0 Then
                            result = False
                            Image5.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotBusiness + " 1" + "\n"
                        ElseIf ddlBusiness1.SelectedValue = 99 Then
                            If txtBizOther1.Text.Trim = "" Then
                                result = False
                                Image5.ImageUrl = "~/img/icon/cancel.png"
                                strMsg = strMsg + Resources.resMsgAlertKYC.NotBusinessOther + " 1" + "\n"
                            Else
                                Image5.ImageUrl = "~/img/icon/accept.png"
                            End If
                        Else
                            Image5.ImageUrl = "~/img/icon/accept.png"
                        End If
                    ElseIf ddlOccupation1.SelectedValue = 99 Then 'อื่นๆ
                        If txtOccOther1.Text.Trim = "" Then
                            result = False
                            Image5.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotOccupationOther + " 1" + "\n"
                        Else
                            Image5.ImageUrl = "~/img/icon/accept.png"
                        End If
                    Else
                        Image5.ImageUrl = "~/img/icon/accept.png"
                    End If
                End If

                If Not ddlOccupation2.SelectedIndex = 0 Then
                    If ddlOccupation2.SelectedValue = 98 Then 'เจ้าของ
                        If ddlBusiness2.SelectedIndex = 0 Then
                            result = False
                            Image5.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotBusiness + " 2" + "\n"
                        ElseIf ddlBusiness2.SelectedValue = 99 Then
                            If txtBizOther2.Text.Trim = "" Then
                                result = False
                                Image5.ImageUrl = "~/img/icon/cancel.png"
                                strMsg = strMsg + Resources.resMsgAlertKYC.NotBusinessOther + " 2" + "\n"
                            Else
                                Image5.ImageUrl = "~/img/icon/accept.png"
                            End If
                        Else
                            Image5.ImageUrl = "~/img/icon/accept.png"
                        End If
                    ElseIf ddlOccupation2.SelectedValue = 99 Then 'อื่นๆ
                        If txtOccOther2.Text.Trim = "" Then
                            result = False
                            Image5.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotOccupationOther + " 2" + "\n"
                        Else
                            Image5.ImageUrl = "~/img/icon/accept.png"
                        End If
                    Else
                        Image5.ImageUrl = "~/img/icon/accept.png"
                    End If
                End If

                If Not ddlOccupation3.SelectedIndex = 0 Then
                    If ddlOccupation3.SelectedValue = 98 Then 'เจ้าของ
                        If ddlBusiness3.SelectedIndex = 0 Then
                            result = False
                            Image5.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotBusiness + " 3" + "\n"
                        ElseIf ddlBusiness3.SelectedValue = 99 Then
                            If txtBizOther3.Text.Trim = "" Then
                                result = False
                                Image5.ImageUrl = "~/img/icon/cancel.png"
                                strMsg = strMsg + Resources.resMsgAlertKYC.NotBusinessOther + " 3" + "\n"
                            Else
                                Image5.ImageUrl = "~/img/icon/accept.png"
                            End If
                        Else
                            Image5.ImageUrl = "~/img/icon/accept.png"
                        End If
                    ElseIf ddlOccupation3.SelectedValue = 99 Then 'อื่นๆ
                        If txtOccOther3.Text.Trim = "" Then
                            result = False
                            Image5.ImageUrl = "~/img/icon/cancel.png"
                            strMsg = strMsg + Resources.resMsgAlertKYC.NotOccupationOther + " 3" + "\n"
                        Else
                            Image5.ImageUrl = "~/img/icon/accept.png"
                        End If
                    Else
                        Image5.ImageUrl = "~/img/icon/accept.png"
                    End If
                End If
            End If


            If ddlIncomeSource1.SelectedIndex = 0 Then
                result = False
                Image6.ImageUrl = "~/img/icon/cancel.png"
                strMsg = strMsg + Resources.resMsgAlertKYC.NotIncomeSource + " แหล่งที่ 1" + "\n"
            Else
                Image6.ImageUrl = "~/img/icon/accept.png"
            End If

            'If ddlPosition.SelectedIndex = 0 Then
            '    result = False
            '    Image7.ImageUrl = "~/img/icon/cancel.png"
            '    strMsg = strMsg + Resources.resMsgAlertKYC.NotPosition + "\n"
            'Else
            '    Image7.ImageUrl = "~/img/icon/accept.png"
            'End If

            If result = False Then
                statusValidation()
            End If

            clsCheckLanguage = Nothing

            Return result
        Catch ex As Exception
            WriteError(ex, "CheckBeforeCompile", "NonIndividualBoard")

            Throw ex
        End Try
    End Function

    Private Sub statusValidation()

        Image1.Visible = True
        Image2.Visible = True
        Image3.Visible = True
        Image4.Visible = True
        Image5.Visible = True
        Image6.Visible = True

    End Sub

    Private Sub statusValidationFalse()

        Image1.Visible = False
        Image2.Visible = False
        Image3.Visible = False
        Image4.Visible = False
        Image5.Visible = False
        Image6.Visible = False

    End Sub

    Private Sub compileCDD()
        Try
            'btnSave.Visible = True
            btnReport.Visible = True

            Dim strReason = ""
            Dim risk As Integer

            risk = clsRiskLevel.riskLevel(txtUniqueID.Text.Trim, txtNameTh1.Text.Trim, txtNameTh2.Text.Trim, txtNameTh3.Text.Trim, txtNameEn1.Text.Trim, txtNameEn2.Text.Trim, txtNameEn3.Text.Trim, ddlOccupation1.SelectedValue, ddlOccupation1.SelectedItem.Text, ddlOccupation2.SelectedValue, ddlOccupation2.SelectedItem.Text, ddlOccupation3.SelectedValue, ddlOccupation3.SelectedItem.Text, ddlBusiness1.SelectedValue, ddlBusiness1.SelectedItem.Text, ddlBusiness2.SelectedValue, ddlBusiness2.SelectedItem.Text, ddlBusiness3.SelectedValue, ddlBusiness3.SelectedItem.Text, ddlNationality.SelectedValue, ddlNationality.SelectedItem.Text, ddlIncomeSource1.SelectedValue, ddlIncomeSource1.SelectedItem.Text, ddlIncomeSource2.SelectedValue, ddlIncomeSource2.SelectedItem.Text, ddlIncomeSource3.SelectedValue, ddlIncomeSource3.SelectedItem.Text, strReason)

            If Not Session("Sanction") = Nothing Then
                risk = 3
                strReason = clsRiskLevel.sumString(strReason, Session("Sanction"))
                Session("Sanction") = Nothing
            End If

            If Not txtReasonSAS.Text = "" Then
                If hdfAML.Value > risk Then
                    risk = hdfAML.Value
                End If
            End If

            If risk = 1 Then
                txtRiskLevel.Text = "ลูกค้ามีความเสี่ยงระดับ 1"
                lblLevel.Text = 1
                txtReason.Text = ""
                txtRiskLevel.BackColor = Drawing.Color.LawnGreen
            ElseIf risk = 2 Then
                txtRiskLevel.Text = "ลูกค้ามีความเสี่ยงระดับ 2"
                lblLevel.Text = 2
                txtReason.Text = strReason
                txtRiskLevel.BackColor = Drawing.Color.Orange
            ElseIf risk = 3 Then
                txtRiskLevel.Text = "ลูกค้ามีความเสี่ยงระดับ 3"
                lblLevel.Text = 3
                txtReason.Text = strReason
                txtRiskLevel.BackColor = Drawing.Color.OrangeRed
            End If

            Session("strReason") = strReason

            If Not Request.QueryString("Type") = "1" Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" & Resources.resMsgKYC.msgLevel & risk & "')", True)
            End If

        Catch ex As Exception
            WriteError(ex, "compileCDD", "NonIndividualBoard")
            Throw ex
        End Try
    End Sub

    Private Function chkCardIdDuplicate(ByVal strUniqueID As String) As Boolean
        Try
            Dim blnDup As Boolean = True

            Dim qryDup = (From tblDup In ds.Tables("dsCustomerCom") Where tblDup.Item("UNIQUEID") = strUniqueID).ToList

            If Not (qryDup.Count = 0) Then
                blnDup = False
            End If

            'If (strUniqueID.Trim = txtUniqueID.Text.Trim) Then
            '    blnDup = False
            'End If

            qryDup = Nothing

            Return blnDup
        Catch ex As Exception
            WriteError(ex, "chkCardIdDuplicate", "NonIndividualBoard")
            Throw ex
        End Try
    End Function

    Sub saveData()
        Try
            Dim drCust As DataRow = ds.Tables("dsCustomerCom").NewRow
            If lblCustSEQ.Text = 0 Then
                drCust("CustSEQ") = Now.Millisecond + Now.Minute
                drCust("CreateBy") = "AutoGenPK"
            Else
                drCust("CustSEQ") = lblCustSEQ.Text
                drCust("CreateBy") = " "
            End If

            drCust("CustType") = 1 '
            drCust("CustSubType") = 1
            drCust("CUSTIDTYPE") = ddlUniqueType.SelectedValue
            drCust("AMLCDD") = CInt(lblLevel.Text.Trim)
            drCust("AMLREASON") = CStr(txtReason.Text.Trim)
            drCust("UNIQUEID") = txtUniqueID.Text.Trim
            drCust("ThPreFix") = ddlPrefixTH.SelectedValue
            drCust("ThFirstName") = txtNameTh1.Text.Trim
            drCust("ThMidName") = txtNameTh2.Text.Trim
            drCust("ThLastName") = txtNameTh3.Text.Trim
            drCust("ENPreFix") = ddlPrefixEN.SelectedValue
            drCust("EnFirstName") = txtNameEn1.Text.Trim
            drCust("EnMidName") = txtNameEn2.Text.Trim
            drCust("EnLastName") = txtNameEn3.Text.Trim
            If Not ddlOccupation1.SelectedIndex = 0 Then
                drCust("OCCUPATIONTYPE1") = ddlOccupation1.SelectedValue
                drCust("OCCUPATIONTYPEOTHER1") = txtOccOther1.Text.Trim
            Else
                drCust("OCCUPATIONTYPE1") = DBNull.Value
                drCust("OCCUPATIONTYPEOTHER1") = ""
            End If
            If Not ddlOccupation2.SelectedIndex = 0 Then
                drCust("OCCUPATIONTYPE2") = ddlOccupation2.SelectedValue
                drCust("OCCUPATIONTYPEOTHER2") = txtOccOther2.Text.Trim
            Else
                drCust("OCCUPATIONTYPE2") = DBNull.Value
                drCust("OCCUPATIONTYPEOTHER2") = ""
            End If
            If Not ddlOccupation3.SelectedIndex = 0 Then
                drCust("OCCUPATIONTYPE3") = ddlOccupation3.SelectedValue
                drCust("OCCUPATIONTYPEOTHER3") = txtOccOther3.Text.Trim
            Else
                drCust("OCCUPATIONTYPE3") = DBNull.Value
                drCust("OCCUPATIONTYPEOTHER3") = ""
            End If

            If Not ddlBusiness1.SelectedIndex = 0 Then
                drCust("BIZTYPE1") = ddlBusiness1.SelectedValue
                drCust("BIZTYPEOTHER1") = txtBizOther1.Text.Trim
            Else
                drCust("BIZTYPE1") = DBNull.Value
                drCust("BIZTYPEOTHER1") = ""
            End If
            If Not ddlBusiness2.SelectedIndex = 0 Then
                drCust("BIZTYPE2") = ddlBusiness2.SelectedValue
                drCust("BIZTYPEOTHER2") = txtBizOther2.Text.Trim
            Else
                drCust("BIZTYPE2") = DBNull.Value
                drCust("BIZTYPEOTHER2") = ""
            End If
            If Not ddlBusiness3.SelectedIndex = 0 Then
                drCust("BIZTYPE3") = ddlBusiness3.SelectedValue
                drCust("BIZTYPEOTHER3") = txtBizOther3.Text.Trim
            Else
                drCust("BIZTYPE3") = DBNull.Value
                drCust("BIZTYPEOTHER3") = ""
            End If

            drCust("BIZDESC1") = txtDes1.Text.Trim
            drCust("BIZDESC2") = txtDes2.Text.Trim
            drCust("BIZDESC3") = txtDes3.Text.Trim

            drCust("Nationality") = ddlNationality.SelectedValue
            drCust("IncomeSource1") = ddlIncomeSource1.SelectedValue
            If Not ddlIncomeSource2.SelectedIndex = 0 Then
                drCust("IncomeSource2") = ddlIncomeSource2.SelectedValue
            End If
            If Not ddlIncomeSource3.SelectedIndex = 0 Then
                drCust("IncomeSource3") = ddlIncomeSource3.SelectedValue
            End If

            drCust("POCODE") = ddlPosition.SelectedValue
            drCust("PONAME") = ddlPosition.SelectedItem.Text
            ' drCust("ETL_STATUS") = "N"
            ds.Tables("dsCustomerCom").Rows.Add(drCust)
        Catch ex As Exception
            WriteError(ex, "SaveData", "NonIndividualBoard")
            Throw ex
        End Try
    End Sub

    Sub updateData()
        Try
            ds.Tables("dsCustomerCom").Rows(index)("AMLCDD") = CInt(lblLevel.Text.Trim) 'ประเภทความเสี่ยง รอประมวลผล
            ds.Tables("dsCustomerCom").Rows(index)("AMLREASON") = CStr(txtReason.Text.Trim)
            ds.Tables("dsCustomerCom").Rows(index)("CUSTIDTYPE") = ddlUniqueType.SelectedValue
            ds.Tables("dsCustomerCom").Rows(index)("UNIQUEID") = txtUniqueID.Text.Trim
            ds.Tables("dsCustomerCom").Rows(index)("ThPreFix") = ddlPrefixTH.SelectedValue
            ds.Tables("dsCustomerCom").Rows(index)("ThFirstName") = txtNameTh1.Text.Trim
            ds.Tables("dsCustomerCom").Rows(index)("ThMidName") = txtNameTh2.Text.Trim
            ds.Tables("dsCustomerCom").Rows(index)("ThLastName") = txtNameTh3.Text.Trim
            ds.Tables("dsCustomerCom").Rows(index)("ENPreFix") = ddlPrefixEN.SelectedValue
            ds.Tables("dsCustomerCom").Rows(index)("EnFirstName") = txtNameEn1.Text.Trim
            ds.Tables("dsCustomerCom").Rows(index)("EnMidName") = txtNameEn2.Text.Trim
            ds.Tables("dsCustomerCom").Rows(index)("EnLastName") = txtNameEn3.Text.Trim
            If Not ddlOccupation1.SelectedIndex = 0 Then
                ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPE1") = ddlOccupation1.SelectedValue
                ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPEOTHER1") = txtOccOther1.Text.Trim
            Else
                ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPE1") = DBNull.Value
                ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPEOTHER1") = ""
            End If
            If Not ddlOccupation2.SelectedIndex = 0 Then
                ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPE2") = ddlOccupation2.SelectedValue
                ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPEOTHER2") = txtOccOther2.Text.Trim
            Else
                ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPE2") = DBNull.Value
                ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPEOTHER2") = ""
            End If
            If Not ddlOccupation3.SelectedIndex = 0 Then
                ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPE3") = ddlOccupation3.SelectedValue
                ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPEOTHER3") = txtOccOther3.Text.Trim
            Else
                ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPE3") = DBNull.Value
                ds.Tables("dsCustomerCom").Rows(index)("OCCUPATIONTYPEOTHER3") = ""
            End If

            If Not ddlBusiness1.SelectedIndex = 0 Then
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE1") = ddlBusiness1.SelectedValue
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER1") = txtBizOther1.Text.Trim
            Else
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE1") = DBNull.Value
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER1") = ""
            End If
            If Not ddlBusiness2.SelectedIndex = 0 Then
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE2") = ddlBusiness2.SelectedValue
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER2") = txtBizOther2.Text.Trim
            Else
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE2") = DBNull.Value
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER2") = ""
            End If
            If Not ddlBusiness3.SelectedIndex = 0 Then
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE3") = ddlBusiness3.SelectedValue
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER3") = txtBizOther3.Text.Trim
            Else
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPE3") = DBNull.Value
                ds.Tables("dsCustomerCom").Rows(index)("BIZTYPEOTHER3") = ""
            End If

            ds.Tables("dsCustomerCom").Rows(index)("BIZDESC1") = txtDes1.Text.Trim
            ds.Tables("dsCustomerCom").Rows(index)("BIZDESC2") = txtDes2.Text.Trim
            ds.Tables("dsCustomerCom").Rows(index)("BIZDESC3") = txtDes3.Text.Trim

            ds.Tables("dsCustomerCom").Rows(index)("Nationality") = ddlNationality.SelectedValue
            ds.Tables("dsCustomerCom").Rows(index)("IncomeSource1") = ddlIncomeSource1.SelectedValue
            If Not ddlIncomeSource2.SelectedIndex = 0 Then
                ds.Tables("dsCustomerCom").Rows(index)("IncomeSource2") = ddlIncomeSource2.SelectedValue
            Else
                ds.Tables("dsCustomerCom").Rows(index)("IncomeSource2") = DBNull.Value
            End If
            If Not ddlIncomeSource3.SelectedIndex = 0 Then
                ds.Tables("dsCustomerCom").Rows(index)("IncomeSource3") = ddlIncomeSource3.SelectedValue
            Else
                ds.Tables("dsCustomerCom").Rows(index)("IncomeSource3") = DBNull.Value
            End If

            ds.Tables("dsCustomerCom").Rows(index)("POCODE") = ddlPosition.SelectedValue
            ds.Tables("dsCustomerCom").Rows(index)("PONAME") = ddlPosition.SelectedItem.Text
            'ds.Tables("dsCustomerCom").Rows(index)("ETL_STATUS") = "N"

            ds.Tables("dsCustomerCom").Rows(index).AcceptChanges()
        Catch ex As Exception
            WriteError(ex, "updateData", "NonIndividualBoard")
            Throw ex
        End Try
    End Sub

    Private Sub SaveLogPrint(ByVal index As Integer)
        Try
            Dim program As String = ""
            If CInt(Session("KYC")) = 1 Then
                program = "M11"
            ElseIf CInt(Session("KYC")) = 2 Then
                program = "M21"
            ElseIf CInt(Session("KYC")) = 3 Then
                program = "M31"
            Else
                program = "M41"
            End If

            Dim desc As String = ""
            If index = 1 Then
                desc = "พิมพ์ฟอร์ม KYC"
            Else
                desc = "พิมพ์ผลประเมินความเสี่ยง (ผู้ถือหุ้น)"
            End If

            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction(txtUniqueID.Text.Trim, clsSessionMenuRight.getUserName, 2, desc, program)
            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

#End Region

    Protected Sub btnEditCompile_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEditCompile.Click
        If (Panel2.Enabled = False) Then
            Panel2.Enabled = True
            btnCompile.Visible = True
            btnEditCompile.Visible = False
            btnReport.Visible = False
        Else
            Panel2.Enabled = False
            btnCompile.Visible = False
            btnEditCompile.Visible = True
            btnReport.Visible = True
        End If
    End Sub

  
End Class
